//
//  MHNearCollectionViewModel.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/9/21.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHNearCollectionViewModel.h"
#import "MHWebViewModel.h"
#import "MHNearByModel.h"

@implementation MHNearCollectionViewModel
-(void)initialize
{
    [super initialize];
    self.shouldPullDownToRefresh = YES;
    self.title = @"附近圈子";
    self.shouldRequestRemoteDataOnViewDidLoad = false;
    self.didSelectCommand  = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(NSIndexPath *indexPath) {
        MHNearByModel *nearBy =  self.datas[indexPath.row];
        
        MHDiscoverHomeModel *model = [MHDiscoverHomeModel new];
        model.circleId = nearBy.circleId;
        model.isInCircle = nearBy.isInCircle;
        model.circleName = nearBy.title;
        model.payType = nearBy.payType;
        model.circleCode = nearBy.circleCode;
        [AXAppDelegate sharedDelegate].currentDiscoverModel = model;
        NSString *detailUrl =  [NSString stringWithFormat:@"%@join-circle-app.html?circleId=",[MHConfigureManager h5BaseUrl]];
        NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"%@%ld&userId=%d",detailUrl,(long)nearBy.circleId,[MHHTTPService sharedInstance].currentUser.userId]];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        MHWebViewModel * webViewModel = [[MHWebViewModel alloc] initWithServices:self.services params:@{MHViewModelRequestKey:request}];
        webViewModel.showBottomButton = YES;
        [self.services pushViewModel:webViewModel animated:YES];
        return [RACSignal empty];
        
    }];
    
    
}

-(RACSignal *)customSignalWithPage:(NSInteger)page
{
    if(!self.location)
    {
        return [RACSignal empty];
    }
    return [self.services.client getNearbyCirclePagedListWithLocationLat:self.location.coordinate.latitude locationLon:self.location.coordinate.longitude pageNum:page pageSize:self.perPage];
}
@end
